package com.zqh.irmadscore.controller;


import com.zqh.irmadscore.model.dto.MainItemDTO;
import com.zqh.irmadscore.service.MainItemService;
import com.zqh.irmadscore.utils.resultUtils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.*;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/mainItems")
@Tag(name = "设备管理")
public class MainItemController {


    private final MainItemService mainItemService;

    /**
     * 创建设备。
     *
     * @param dto 包含主项及其数据项信息的DTO对象
     * @return 操作结果，返回成功状态码
     */
    @PostMapping
    @Operation(summary = "创建设备")
    public Result<Void> create(@RequestBody MainItemDTO dto) {


        mainItemService.saveMainItemWithDataItems(dto);

        return Result.ok();
    }


    @GetMapping()
    @Operation(summary = "查询所有主设备")
    public Result<List<MainItemDTO>> getAll() {

        System.out.println("111");
        List<MainItemDTO> dto = mainItemService.getAllMainItem();

        return Result.ok(dto);
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据主设备ID获取设备详情")
    public Result<MainItemDTO> getById(@PathVariable Integer id) {
        MainItemDTO dto = mainItemService.getMainItemWithDataItems(id);

        return Result.ok(dto);
    }




    @PutMapping
    @Operation(summary = "更新设备信息")
    public Result<Void> update(@RequestBody MainItemDTO dto) {
        mainItemService.updateMainItemWithDataItems(dto);


        return Result.ok();
    }





//




}
